home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / vs / browser / cpb10ebx.exe / DATA.Z / sphere.java < prev    next >
Text File  |  1996-10-16  |  1KB  |  67 lines

  1. /*
  2.  *    File    : sphere.java (Script for Community Place)
  3.  *    Version : 2.0- 1996.09.11
  4.  *    Auther  : cori co.
  5.  *
  6.  *    Copyright(C) 1996 Sony Corporation. All rights reserved.
  7.  */
  8.  
  9. import vrml.*;
  10. import vrml.field.*;
  11. import vrml.node.*;
  12. import java.util.*;
  13. //import vs.*;
  14.  
  15.  
  16. /* This is a sample script for event handler.*/
  17. public class sphere extends Script {
  18.     SFColor    SphereDiffuseColor;
  19.     boolean    SphereColorFlg = false;
  20.  
  21.  
  22.     /*
  23.      * Initialize
  24.      */
  25.     public void initialize() {
  26.         SphereDiffuseColor = (SFColor)getEventOut( "SphereDiffuseColor" );
  27.     }
  28.  
  29.  
  30.     /*
  31.      * eventIn
  32.      */
  33.     public void processEvent( Event e ) {
  34.         String name = e.getName();
  35.  
  36.         if ( name.equals( "SphereClicked" )) {
  37.             SphereClicked( (ConstSFBool)e.getValue() );
  38.         }
  39.     }
  40.  
  41.  
  42.     /*
  43.      * Clicked on the sphere
  44.      */
  45.     void SphereClicked( ConstSFBool state ) {
  46.         float col[] = new float[3];
  47.  
  48.         if ( !state.getValue() ) {            /* != mouseDown */
  49.             if ( SphereColorFlg == false ) {
  50.                 col[0] = 1.0f;
  51.                 col[1] = 0.0f;
  52.                 col[2] = 0.0f;
  53.                 SphereColorFlg = true;
  54.             } else {
  55.                 col[0] = 0.0f;
  56.                 col[1] = 0.8f;
  57.                 col[2] = 0.8f;
  58.                 SphereColorFlg = false;
  59.             }
  60.             SphereDiffuseColor.setValue( col );
  61.         }
  62.     }
  63. }
  64.  
  65.  
  66.  
  67.